package com.gezi.admin.config.application;

import cn.hutool.core.io.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 使用方法：ApplicationUtil.baseurl
 * @Author 格子代码
 * @createDate 2024/2/10 09:00
 * @contact 1424529270@qq.com
 */
@Component
public class ApplicationUtil {

    public static String contextPath = ""; //基础路径

    public static String fileLocalPath = "";//文件-本地路径

    public static String fileWebUrl = "";//文件-网络路径

    public static String webUrl = "";//上传本地路径


    @Value("${server.servlet.context-path}")
    public void setContextPath(String contextPath) {
        ApplicationUtil.contextPath = contextPath;
    }

    @Value("${gezi.fileLocalPath}")
    public void setFileLocalPath(String uploadLocalPath) {
        if(FileUtil.isAbsolutePath(uploadLocalPath)){
            ApplicationUtil.fileLocalPath = uploadLocalPath.replaceAll("\\\\","/");
        }else{
            ApplicationUtil.fileLocalPath = System.getProperty("user.dir").replaceAll("\\\\","/") + "/" + uploadLocalPath;
        }
    }

    @Value("${gezi.weburl}")
    public void setWebUrl(String webUrl) {
        ApplicationUtil.webUrl = webUrl;
        ApplicationUtil.fileWebUrl = webUrl + "/server/file";
    }
}
